#!/bin/bash
set -e
source smsg.sh
WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BASEOUT="$WDIR/apk"
ANDROID_TARGET=android-19

MAKE_ARG=$@
if [ -z "$MAKE_ARG" ]; then
    MAKE_ARG=all
fi

BUILD_COUNT=0
UNBUILD_COUNT=0

echo "build argument is:"$MAKE_ARG

if [[ ( $MAKE_ARG == all ) ]]
then
	if [ -d $BASEOUT ]; then
		rm -rf $BASEOUT
	fi
	mkdir $BASEOUT
fi

# patch source files
#./pp.sh

if [[ ( $MAKE_ARG == *FarmerAssistant* )||( $MAKE_ARG == all ) ]]; then
#FarmerAssistant
FarmerAssistant=$WDIR/../FarmerAssistant
cd $FarmerAssistant
android update project -p .
ant clean
ant release
cp bin/FarmerAssistant-release.apk $BASEOUT/FarmerAssistant.apk
let "BUILD_COUNT += 1"
else
let "UNBUILD_COUNT += 1"
fi



if [ $BUILD_COUNT -eq 0 ]; then
	SMSG "Nonthing to build, maybe your input is incorrect" 1
	exit 1
fi

echo --------------------------------------------------------------
SMSG "RESULT== BUILD : $BUILD_COUNT---UNBUILD : $UNBUILD_COUNT" 3
SMSG "Done! We love linux, we love UBUNTU!" 3
echo --------------------------------------------------------------
